import 'package:flutter/material.dart';
import './res/listDate.dart';

//ListView列表组件
void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('ListView动态列表 list,maps实现 -- 数据抽离出去'),
          backgroundColor: Colors.pink[50],
        ),
        body: MyHomePage(),
      ),
    );
  }
}

class MyHomePage extends StatelessWidget {
  MyHomePage({super.key});

  @override
  Widget build(BuildContext context) {
    print(listDate);
    return ListView.builder(
      itemCount: listDate.length,//循环次数
      itemBuilder: (content, index) { //提供当前构建项的上下文环境，索引
        return Column(
          children: [
            ListTile(
              title: Text('${listDate[index]['title']}'),
              subtitle: Text('${listDate[index]['date']}'),
              leading: Image.network('${listDate[index]['imageUrl']}'),
            ),
            Divider(),
          ],
        );
      },
    );
  }
}
